<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>往来财务</title>
		<link rel="stylesheet" href="../../layui/css/layui.css" media="all">
	</head>

	<body>
		<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
			<ul class="layui-tab-title">
				<li class="layui-this">供货商所有单据</li>
				<li>供货商供货情况表</li>
				<li>供货商商品销售情况</li>
				<li>供货商账务</li>
			</ul>

			<div class="layui-tab-content" style="height: 100px;">
				<!--供货商所有单据-->
				<div class="layui-tab-item layui-show">
					<div class="layui-panel" style="margin: 15px;padding-top: 20px;">
					<form class="layui-form">
						<div class="layui-form-item layui-inline">
							<div class="layui-inline">
								<label class="layui-form-label ">查询时间</label>
								<div class="layui-inline" id="test6">
									<div class="layui-input-inline">
										<input type="text" autocomplete="off" id="test-startDate-1" class="layui-input"
											placeholder="开始日期" name="">
									</div>
									<div class="layui-form-mid">-</div>
									<div class="layui-input-inline">
										<input type="text" autocomplete="off" id="test-endDate-1" class="layui-input"
											placeholder="结束日期">
									</div>
								</div>
							</div>
						</div>
						<div class="layui-form-item layui-inline" style="margin-top:-10px;">
							<label class="layui-form-label">供货商名称</label>
							<div class="layui-input-inline">
								<input type="hidden" name="supId"/>
								<input type="hidden" name="supId-1"/>
								<input type="hidden" name="supId-2"/>
								<input type="text" name="supName-1" id="demo-1" lay-verify="required" placeholder="请输入"
																				  autocomplete="off" class="layui-input">
							</div>
							<button type="button" class="layui-btn layui-btn-radius" id="find-1">查询</button>
						</div>
					</form>
					</div>
					<fieldset class="layui-elem-field layui-field-title">
						<legend>往来账务列表</legend>
					</fieldset>
					<div class="layui-panel" style="margin: 15px;border: 0px;">
					<table class="layui-hide" id="test" lay-filter="test" style=""></table>
					<div style="color: red;"><span style="margin-left: 70px;">单据的详细信息如下：</span></div>
					<table class="layui-hide" id="tests" lay-filter="tests"></table>
					</div>
				</div>
				<!--供货商供货情况表-->
				<div class="layui-tab-item">
					<div class="layui-panel" style="margin: 15px;padding-top: 20px;">
						<form class="layui-form">
							<div class="layui-form-item layui-inline">
								<div class="layui-inline">
									<label class="layui-form-label ">查询时间</label>
									<div class="layui-inline" id="test7">
										<div class="layui-input-inline">
											<input type="text" autocomplete="off" id="test-startDate-2" class="layui-input"
												   placeholder="开始日期" name="">
										</div>
										<div class="layui-form-mid">-</div>
										<div class="layui-input-inline">
											<input type="text" autocomplete="off" id="test-endDate-2" class="layui-input"
												   placeholder="结束日期">
										</div>
									</div>
								</div>
							</div>
							<div class="layui-form-item layui-inline" style="margin-top:-10px;">
								<label class="layui-form-label">供货商名称</label>
								<div class="layui-input-inline">
									<input type="text" name="supName-2" id="demo-2" lay-verify="required" placeholder="请输入"
										   autocomplete="off" class="layui-input">
								</div>
								<button type="button" class="layui-btn layui-btn-radius" id="find-2">查询</button>
							</div>
							<div class="layui-form-item layui-inline">
								<div class="layui-input-block" style="margin: 0px 0px 8px 30px;">
									<input type="radio" name="switchTable" value="1" title="汇总表" lay-filter="switchTable" checked="">
									<input type="radio" name="switchTable" value="2" title="流水表" lay-filter="switchTable">
								</div>
							</div>
						</form>
						<table class="layui-hide" id="document-1"></table>
					</div>

				</div>
				<!--供货商商品销售情况-->
				<div class="layui-tab-item">
					<div class="layui-panel" style="margin: 15px;padding-top: 20px;">
						<form class="layui-form">
							<div class="layui-form-item layui-inline">
								<div class="layui-inline">
									<label class="layui-form-label ">查询时间</label>
									<div class="layui-inline" id="test8">
										<div class="layui-input-inline">
											<input type="text" autocomplete="off" id="test-startDate-3" class="layui-input"
												   placeholder="开始日期" name="">
										</div>
										<div class="layui-form-mid">-</div>
										<div class="layui-input-inline">
											<input type="text" autocomplete="off" id="test-endDate-3" class="layui-input"
												   placeholder="结束日期">
										</div>
									</div>
								</div>
							</div>
							<div class="layui-form-item layui-inline" style="margin-top:-10px;">
								<label class="layui-form-label">供货商名称</label>
								<div class="layui-input-inline">
									<input type="text" name="supName-3" id="demo-3" lay-verify="required" placeholder="请输入"
										   autocomplete="off" class="layui-input">
								</div>
								<button type="button" class="layui-btn layui-btn-radius" id="find-3">查询</button>
							</div>

						</form>
						<table class="layui-hide" id="document-2"></table>
					</div>

				</div>
				<!--供货商账务-->
				<div class="layui-tab-item">
					<div class="layui-panel" style="margin: 15px;padding-top: 13px;">
						<!--<div style="display: inline-block;margin-left: 400px">供货商商品销售情况</div>
						<div style="float: right;margin-right: 300px">供货商账务情况</div>-->
						<table class="layui-hide" id="document-3"></table>
					</div>
				</div>
			</div>
		</div>


<!--
		<div id="up" style="display: none;">
			<fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
				<legend>修改供货商</legend>
			</fieldset>
			<form class="layui-form" id="upForm" lay-filter="upForm" action="">
				<div class="layui-form-item">
					<label class="layui-form-label">供货商名称</label>
					<div class="layui-input-block">
						<input style="width: 515px;" type="text" name="supName" lay-verify="title" autocomplete="off"
							value="" class="layui-input">
					</div>
					<div class="layui-inline" style="margin-top: 10px;">
						<label class="layui-form-label">供货商类型</label>
						<div class="layui-input-inline">
							<select name="quiz">
								<option value="">请选择问题</option>
								<optgroup label="城市记忆">
									<option value="你工作的第一个城市">你工作的第一个城市</option>
								</optgroup>
								<optgroup label="学生时代">
									<option value="你的工号">你的工号</option>
									<option value="你最喜欢的老师">你最喜欢的老师</option>
								</optgroup>
							</select>
						</div>
					</div>

					<div class="layui-inline" style="margin-top: 10px;">
						<label class="layui-form-label">所属地区</label>
						<div class="layui-input-inline">
							<select name="modules" lay-verify="required" lay-search="">
								<option value="">直接选择或搜索选择</option>
								<option value="1">layer</option>
								<option value="2">form</option>
								<option value="3">layim</option>
							</select>
						</div>
					</div>

					<div class="layui-inline" style="margin-top: 10px;">
						<label class="layui-form-label">联系人</label>
						<div class="layui-input-inline">
							<input type="tel" name="supPeople" lay-verify="required|phone" autocomplete="off"
								class="layui-input">
						</div>
					</div>
					<div class="layui-inline" style="margin-top: 10px;">
						<label class="layui-form-label">联系电话</label>
						<div class="layui-input-inline">
							<input type="text" name="supPhone" lay-verify="email" autocomplete="off"
								class="layui-input">
						</div>
					</div>

					<div class="layui-inline" style="margin-top: 10px;">
						<label class="layui-form-label">联系地址</label>
						<div class="layui-input-block">
							<input style="width: 515px;" type="text" name="" lay-verify="title"
								autocomplete="off" value="" class="layui-input">
						</div>
					</div>

					<div class="layui-inline" style="margin-top: 10px;">
						<label class="layui-form-label">经营范围</label>
						<div class="layui-input-block">
							<input style="width: 515px;" type="text" name="" lay-verify="title"
								autocomplete="off" value="" class="layui-input">
						</div>
					</div>
					<div class="layui-inline" style="margin-top: 10px;">
						<label class="layui-form-label">备注</label>
						<div class="layui-input-block">
							<textarea placeholder="请输入内容" class="layui-textarea" style="width: 515px;"></textarea>
						</div>
					</div>

					<div class="layui-input-block">
						<input type="checkbox" name="like1[write]" lay-skin="primary" title="默认供货商" checked="">
					</div>

					<div class="layui-input-block">
						<button type="submit" class="layui-btn layui-btn-normal"
							id="LAY-component-form-setval">保存</button>
						<button type="button" lay-event="exit" class="layui-btn layui-btn-normal"
							id="exit">退出</button>
					</div>
				</div>
			</form>
		</div>
		<div id="jo" style="display: none;">
			<fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
				<legend>付款单(供货商)</legend>
			</fieldset>
			<form class="layui-form" id="joForm" lay-filter="joForm" action="">
				<div style="width:510px;height:40px;border: 1px solid #F0F0F0;text-align: center;margin-left: 68px;padding-top:17px;border-radius: 5px;">供货商名称:<span name="supName"style="color: #0000FF;"></span></div>
			<div class="layui-row" style="padding:15px" >
				<div class="layui-col-md6">
					<div class="layui-form-item">
					    <label class="layui-form-label">欠款金额:</label>
					    <div class="layui-input-block">
					      <input type="text" name="phone" readonly="" autocomplete="off"  class="layui-input" style="border:none; outline:medium;">
					    </div>
					</div>
				</div>
				<div class="layui-col-md6">
					<div class="layui-form-item">
					    <label class="layui-form-label">单号:</label>
					    <div class="layui-input-block">
					      <input type="text" name="purStoId"  autocomplete="off"  readonly=""class="layui-input" style="border:none; outline:medium;">
					    </div>
					</div>
				</div>
				
				<div class="layui-col-md6">
					<div class="layui-form-item">
					    <label class="layui-form-label">付款金额:</label>
					    <div class="layui-input-block">
					      <input type="text" name="custName" autocomplete="off" class="layui-input" >
					    </div>
					</div>
				</div>
				<div class="layui-col-md6">
					<div class="layui-form-item">
					      <div class="layui-inline">
					          <label class="layui-form-label">付款日期</label>
					          <div class="layui-input-block" style="width: 200px;">
					            <input type="text" class="layui-input" id="test19" placeholder="yyyy-MM-dd">
					          </div>
					        </div>
					</div>
				</div>
				
				<div class="layui-col-md6">
					<div class="layui-form-item">
					<label class="layui-form-label">所属地区</label>
					<div class="layui-input-block">
						<select name="modules" lay-verify="required" lay-search="">
							<option value="">直接选择或搜索选择</option>
							<option value="1">layer</option>
							<option value="2">form</option>
							<option value="3">layim</option>
						</select>
					</div>
					</div>
				</div>
				<div class="layui-col-md6">
					<div class="layui-form-item">
					   <label class="layui-form-label">经办人</label>
					   <div class="layui-input-block">
					   	<select name="modules" lay-verify="required" lay-search="">
					   		<option value="">直接选择或搜索选择</option>
					   		<option value="1">layer</option>
					   		<option value="2">form</option>
					   		<option value="3">layim</option>
					   	</select>
					   </div>
					</div>
				</div>
				
				<div class="layui-col-md6">
					<div class="layui-form-item">
					    <label class="layui-form-label">附加说明:</label>
					    <div class="layui-input-block" style="width: 510px;margin-top:20px;" >
					      <input type="text" name="custName" autocomplete="off"  class="layui-input">
					    </div>
					</div>
				</div>
			
			</div>
			</form>
		</div>-->

		<script type="text/html" id="update">
<!--
			<button type="button" lay-submit="" lay-event="update" class="layui-btn layui-btn-normal">修改</button>
-->
			<button type="button" lay-submit="" lay-event="open" class="layui-btn">确定</button>
			<button type="button" lay-submit="" lay-event="exit-1" class="layui-btn">退出</button>
		</script>
		<script src="../../layui/layui.js" charset="utf-8"></script>
		<script src="../../js/lay-config.js?v=1.1.0" charset="utf-8"></script>
		<script>
			layui.use(['jquery', 'form', 'table', 'layer', 'laydate', 'stableSelect'], function() {
				var $ = layui.jquery,
					form = layui.form,
					table = layui.table,
					layer = layui.layer,
					stableSelect = layui.stableSelect,
					laydate = layui.laydate;

                //日期范围
                laydate.render({
                    elem: '#test6'
                    //设置开始日期、日期日期的 input 选择器
                    //数组格式为 2.6.6 开始新增，之前版本直接配置 true 或任意分割字符即可
                    ,
                    range: ['#test-startDate-1', '#test-endDate-1']
                });

				//日期范围
				laydate.render({
					elem: '#test7'
						//设置开始日期、日期日期的 input 选择器
						//数组格式为 2.6.6 开始新增，之前版本直接配置 true 或任意分割字符即可
						,
					range: ['#test-startDate-2', '#test-endDate-2']
				});

                //日期范围
                laydate.render({
                    elem: '#test8'
                    //设置开始日期、日期日期的 input 选择器
                    //数组格式为 2.6.6 开始新增，之前版本直接配置 true 或任意分割字符即可
                    ,
                    range: ['#test-startDate-3', '#test-endDate-3']
                });
                //日期范围
                laydate.render({
                    elem: '#test9'
                    //设置开始日期、日期日期的 input 选择器
                    //数组格式为 2.6.6 开始新增，之前版本直接配置 true 或任意分割字符即可
                    ,
                    range: ['#test-startDate-4', '#test-endDate-4']
                });

                $('#demo-1').bind('input',function () {
                    table.reload('cus-1' , {
                        where: {
                            rad: $("#demo-1").val()
						}
					});
                });

                    stableSelect.render({
                        elem: '#demo-1',
                        width: 100,
                        id: 'cus-1',
                        table: {
                            url: '/searchSupplierInfoController',
                            toolbar: '#update',
                            cols: [
                                [{
                                    type: 'radio'
                                },
                                    {
                                        field: 'supId',
                                        title: '编号'
                                    },
                                    {
                                        field: 'supName',
                                        title: '供货商名称'
                                    },
                                    {
                                        field: 'supPeople',
                                        title: '联系人'
                                    },
                                    {
                                        field: 'supPhone',
                                        title: '联系人电话'
                                    },
                                    {
                                        field: 'supAddress',
                                        title: '联系地址'
                                    }
                                ]
                            ]
                        },
                        done: function(elem, data) {
                            var NEWJSON = []
                            layui.each(data.data, function(index, item) {
                                $('input[name=supId]').val(item.supId)
                                NEWJSON.push(item.supName)
                            });
                            elem.val(NEWJSON.join(","))
                        }
                    });

                stableSelect.render({
                    elem: '#demo-2',
                    width: 100,
                    id: 'cus-2',
                    table: {
                        url: '/searchSupplierInfoController',
                        toolbar: '#update',
                        cols: [
                            [{
                                type: 'radio'
                            },
                                {
                                    field: 'supId',
                                    title: '编号'
                                },
                                {
                                    field: 'supName',
                                    title: '供货商名称'
                                },
                                {
                                    field: 'supPeople',
                                    title: '联系人'
                                },
                                {
                                    field: 'supPhone',
                                    title: '联系人电话'
                                },
                                {
                                    field: 'supAddress',
                                    title: '联系地址'
                                }
                            ]
                        ]
                    },
                    done: function(elem, data) {
                        var NEWJSON = []
                        layui.each(data.data, function(index, item) {
                            $('input[name=supId-1]').val(item.supId)
                            NEWJSON.push(item.supName)
                        });
                        elem.val(NEWJSON.join(","))
                    }
                });

                stableSelect.render({
                    elem: '#demo-3',
                    width: 100,
                    id: 'cus-3',
                    table: {
                        url: '/searchSupplierInfoController',
                        toolbar: '#update',
                        cols: [
                            [{
                                type: 'radio'
                            },
                                {
                                    field: 'supId',
                                    title: '编号'
                                },
                                {
                                    field: 'supName',
                                    title: '供货商名称'
                                },
                                {
                                    field: 'supPeople',
                                    title: '联系人'
                                },
                                {
                                    field: 'supPhone',
                                    title: '联系人电话'
                                },
                                {
                                    field: 'supAddress',
                                    title: '联系地址'
                                }
                            ]
                        ]
                    },
                    done: function(elem, data) {
                        var NEWJSON = []
                        layui.each(data.data, function(index, item) {
                            $('input[name=supId-2]').val(item.supId)
                            NEWJSON.push(item.supName)
                        });
                        elem.val(NEWJSON.join(","))
                    }
                });

				var index;

/*				function update(obj) {
                        index = layer.open({
						type: 1,
						title: "",
						scrollbar: false,
						area: ['700px', '500px'],
						content: $('#up'),
						success: function() {
							var checkStatus = table.checkStatus(obj.config.id);
							var data = checkStatus.data[0];
							form.val('upForm', data);
						}
					})
				}*/
                table.on('toolbar(cus-1)', function(obj) {
                    var checkStatus = table.checkStatus(obj.config.id);
                    switch (obj.event) {
                        case "exit-1":
                            $('.cus-1').css('display' , 'none');
                            break;
                    }

                    if ((checkStatus.data.length ==0 && obj.event=="open") || (checkStatus.data.length ==0 && obj.event=="update")) {
                        layui.use('layer', function() {
                            var layer = layui.layer;
                            layer.msg('请先选择供应商');
                        });
                    } else {
                        switch (obj.event) {
                            case "update":
                                update(obj);
                                break;
                            case "open":
                                $('input[name=supId]').val(checkStatus.data[0].supId);
                                $('input[name=supName-1]').val(checkStatus.data[0].supName);
                                $('.cus-1').css('display' , 'none');
                                break;
                        }
                    }
                });

				table.on('toolbar(cus-2)', function(obj) {
					var checkStatus = table.checkStatus(obj.config.id);
                    switch (obj.event) {
                        case "exit-1":
                            $('.cus-2').css('display' , 'none');
                            break;
                    }

                    if ((checkStatus.data.length ==0 && obj.event=="open") || (checkStatus.data.length ==0 && obj.event=="update")) {
                        layui.use('layer', function() {
                            var layer = layui.layer;
                            layer.msg('请先选择供应商');
                        });
                    } else {
                        switch (obj.event) {
                            case "update":
                                update(obj);
                                break;
                            case "open":
                                $('input[name=supId-1]').val(checkStatus.data[0].supId);
                                $('input[name=supName-2]').val(checkStatus.data[0].supName);
                                $('.cus-2').css('display' , 'none');
                                break;
                        }
                    }
				});

                table.on('toolbar(cus-3)', function(obj) {
                    var checkStatus = table.checkStatus(obj.config.id);
                    switch (obj.event) {
                        case "exit-1":
                            $('.cus-3').css('display' , 'none');
                            break;
                    }

                    if ((checkStatus.data.length ==0 && obj.event=="open") || (checkStatus.data.length ==0 && obj.event=="update")) {
                        layui.use('layer', function() {
                            var layer = layui.layer;
                            layer.msg('请先选择供应商');
                        });
                    } else {
                        switch (obj.event) {
                            case "update":
                                update(obj);
                                break;
                            case "open":
                                $('input[name=supId-2]').val(checkStatus.data[0].supId);
                                $('input[name=supName-3]').val(checkStatus.data[0].supName);
                                $('.cus-3').css('display' , 'none');
                                break;
                        }
                    }
                });

                var testData;

				table.render({
					elem: '#test',
					data:[] /*tpa=https://www.layui.site/test/table/demo1.json*/ ,
					toolbar: '#toolbarDemo',
					title: '用户数据表',
					totalRow: true,
					cols: [
						[ {
							field: 'supName',
							title: '供货商名称',
							width: 120,
							align: 'center',
							totalRowText: '单据合计：<span id=oyh></span>'
						}, {
							field: 'purStoDate',
							title: '日期',
							width: 150,
							align: 'center',
							templet: function(res) {
								var date1 = res.purStoDate;
								var date = new Date(date1);
								var year = date.getFullYear();
								var month = date.getMonth()+1;
								if (month<10){
								    month="0"+month;
								}
								var day = date.getDate();
                                if (day<10){
                                    day="0"+day;
                                }
                                return year+"-"+month+"-"+day;
							}
						}, {
							field: 'purStoId',
							title: '单号',
							align: 'center',
							width: 130,
							totalRowText: '欠款金额：<span id=money></span>'
						}, {
							field: 'sex',
							title: '内容摘要',
							align: 'center',
							width: 130,
                            templet:function (data) {
                                if (data.purStoId.indexOf("CG") == 0){
                                    return "采购进货";
								}else {
                                    return "退货返还";
								}
                            }
						}, {
							field: 'purStoPayable',
							title: '应付金额',
							align: 'center',
							width: 130,
							totalRow: true
						}, {
							field: 'purStoOutof',
							title: '实付金额',
							align: 'center',
							width: 130,
							totalRow: true
						}, {
							field: 'city',
							title: '优惠金额',
							align: 'center',
							width: 130,
							totalRow: true,
                            templet:function (data) {
								return data.purStoPayable - data.purStoOutof;
                            }
						}, {
							field: 'empId',
							title: '经办人',
							width: 130,
							align: 'center',
						}, {
							field: 'empId',
							title: '操作员',
							align: 'center',
							width: 130
						}, {
							fixed: 'right',
							title: '备注',
							toolbar: '#barDemo',
							align: 'center',
							width: 162
						}]
					],
					done: function(obj) {
						$('#oyh').html(obj.data.length);
						var mor = 0;
						var doc = 0;
						for (var i in obj.data) {
							mor += obj.data[i].purStoPayable;
							doc += obj.data[i].purStoOutof;
						}

						if((doc-mor)>=0){$('#money').html(0)};
						if((doc-mor)<0){$('#money').html((mor - doc));}
					}
				});

/*
				//工具栏事件
				table.on('toolbar(test)', function(obj) {
					// var checkStatus = table.checkStatus(obj.config.id);
                            switch (obj.event) {
							case 'getCheckData':
								layer.alert(JSON.stringify(testData));
							layer.confirm('真的删除行么', function(obj){
								$.get("/taige",{purStoId: testData.purStoId},function(row){
									if(row = 1){
										layer.msg("删除成功")
										//表格刷新
										table.reload('test');
										table.reload('tests')
									}else{
										layer.msg("删除失败")
									}
								})
							});
								break;
							case 'getCheckLength':
							if (undefined == testData) {
								layui.use('layer', function() {
									var layer = layui.layer;
									layer.msg('请先选择供应商');
								});
								break;
							}else{
								pay(obj);
								break;}
								
							case 'isAll':
								/!*layer.msg(testData.isAll ? '全选' : '未全选');*!/
                                if("CT"==testData.purStoId.substring(0,2)){
                                    layer.msg("请选择单号以XS开头的数据！");
                                }else if("CJ"==testData.purStoId.substring(0,2)){

                                    $.post("owDetailsOfTheDocumentDatas?purStoId="+testData.purStoId,function (data) {
                                        window.billList = JSON.stringify(JSON.parse(data).data);
                                        layer.open({
                                            type:2,
                                            title: '',
                                            content:"purchase_account.html",
                                            area:['98%','98%'],
                                            success:function (obj) {
                                                window.aaalist = ''
                                            }
                                        });
                                    });
                                }

                                break;
						};
				});
*/


/*					function pay(obj) {
						layer.open({
							type: 1,
							title: "",
							scrollbar: false,
							area: ['650px', '500px'],
							content: $('#jo'),
							success: function() {
								var data = testData;
								form.val('joForm', data);
								$('span[name=supName]').html(data.supName);
								$('input[name=phone]').val($('#money').html());
							}
						})
					}*/

				table.render({
					elem: '#tests',
					data:[],
					cellMinWidth: 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
					totalRow: true,
					cols: [
						[ {
							field: 'proId',
							title: '商品编号',
							width: 120,
							align: 'center',
							totalRowText: '品种合计：<span id=tel></span>'
						}, {
							field: 'proName',
							title: '商品名称',
							width: 150,
							align: 'center',
							templet: function(res) {
								return '<em>' + res.proName + '</em>'
							}
						}, {
							field: 'purStoDescUnit',
							title: '单位',
							align: 'center',
							width: 130
						}, {
							field: 'purStoDescPrice',
							title: '单价',
							align: 'center',
							width: 130,
						}, {
							field: 'purStoDescNum',
							title: '数量',
							align: 'center',
							width: 130,
							totalRow: true
						}, {
							field: '',
							title: '总金额',
							align: 'center',
							width: 130,
                            templet:function (data) {
                                return data.purStoDescPrice * data.purStoDescNum;
                            },
							totalRowText:'￥<span id=zj></span>'
						}, {
							field: 'proSize',
							title: '产品规格',
							align: 'center',
							width: 130,
						}, {
							field: 'proBatchNum',
							title: '产品批号',
							width: 130,
							align: 'center',
						},  {
                            fixed: 'right',
                            title: '备注',
                            align: 'center',
                            width: 162
                        }]
					],
					done: function(obj) {
						$('#tel').html(obj.data.length);
						var num=0;
						for (var i=0;i<obj.data.length;i++){
                            var a=obj.data[i].purStoDescPrice * obj.data[i].purStoDescNum;
                             num +=a;
						}
						$('#zj').html(num);
					}
				});

				//工具栏事件
				table.on('toolbar(upForm)', function(obj) {
					switch (obj.event) {
						case 'exit':
							exit();
							break;
					};
				});

				$('#exit').on('click' , function(){
					exit()
				});

				function exit() {
					layer.close(index);
				}

				  //初始赋值
				  laydate.render({
					elem: '#test19'
					,value: new Date()
					,isInitValue: true
				  });

				$('#find-1').click(
				    function(){
                        var supName = $('#demo-1');
                        if ( "" == supName.val() ) {
                            $('input[name=supId]').val("");
						}
						if(($('#test-startDate-1').val()=="") && ($('#test-endDate-1').val()=="")){
						    layer.msg("请先选择日期");
						}else if(($('#test-startDate-1').val()!="") && ($('#test-endDate-1').val()!="")&&($('input[name=supId]').val()=="")){
                            table.reload('test' , {
                                url: '/searchFinanceController',
                                where: {
                                    startDate: $('#test-startDate-1').val(),
                                    endDate: $('#test-endDate-1').val()
                                }
                            });
						}else{
                            table.reload('test' , {
                                url: '/searchFinanceController',
                                where: {
                                    startDate: $('#test-startDate-1').val(),
                                    endDate: $('#test-endDate-1').val(),
                                    supId: $('input[name=supId]').val()
                                }
                            });
						}

                        table.reload('tests',{
                            url:'',
                            data:[]
                        });
                    }
				)

                //所选商品列表添加样式
                table.on('row(test)', function(obj){
                    testData = obj.data;
                    obj.tr.addClass('layui-bg-green').siblings().removeClass('layui-bg-green');
                });

                table.on('row(tests)', function(obj){
                    testData = obj.data;
                    obj.tr.addClass('layui-bg-green').siblings().removeClass('layui-bg-green');
                });
                /*所选商品列表添加样式*/
                table.on('row(test)', function(obj){
                    testData = obj.data;
                    obj.tr.addClass('layui-bg-green').siblings().removeClass('layui-bg-green');
                    table.reload('tests' , {
                        url: '/searchFinanceDescController',
                        where: {
                            purStoId:testData.purStoId
                        }
                    });
                });

                table.render({
                    elem: '#document-1'
                    ,url: '/searchcollectController'
                    ,height: 353
                    ,cols: [[
                        {field:'proId',align: 'center', width:100, title: '商品编号'}
                        ,{field:'proName',align: 'center', width:120, title: '商品名称'}
                        ,{field:'purStoDescUnit',align: 'center', width:130, title: '单位'}
                        ,{field:'purStoDescNum',align: 'center', width:130, title: '数量'}
                        ,{field:'',align: 'center', width:130, title: '总金额',templet:function (d) {
                                  return parseFloat(d.productInfo.proBid*d.purStoDescNum);
                            }}
                        ,{field:'inveDescInventoryNum',align: 'center', width:130, title: '库存数量',templet:function (data) {
								return data.inveDescInventoryNum;
                                }
                           }
                        ,{field:'purchaseSize',align: 'center', width:130, title: '规格'}
                        ,{field:'purStoDescAgentiaTypeName',align: 'center', width:130, title: '药剂类型'}
                        ,{field:'proPostil',align: 'center', width:130, title: '批准文号'}
                        ,{field:'purStoDescManufacturer',align: 'center', width:130, title: '生产厂商'}
                        ,{field:'supName',align: 'center', width:130, title: '供应商',templet:function (data) {
                                return data.supplierInfo.supName;
                            }}
                        ,{field:'purStoDescComment',align: 'center', width:163, title: '备注'}
                    ]],done:function (data) {
                    }
                });


                var checked = true;

                form.on("radio(switchTable)",function (data) {
                    if (this.value == '1' && checked !=true) {
                        table.render({
                            elem: '#document-1'
                            ,url: '/searchcollectController'
                            ,height: 353
                            ,cols: [[
                                {field:'proId',align: 'center', width:100, title: '商品编号'}
                                ,{field:'proName',align: 'center', width:120, title: '商品名称'}
                                ,{field:'purStoDescUnit',align: 'center', width:130, title: '单位'}
                                ,{field:'purStoDescNum',align: 'center', width:130, title: '数量'}
                                ,{field:'',align: 'center', width:130, title: '总金额',templet:function (d) {
                                        return parseFloat(d.productInfo.proBid*d.purStoDescNum);
                                    }}
                                ,{field:'inveDescInventoryNum',align: 'center', width:130, title: '库存数量',templet:function (data) {
                                        return data.inveDescInventoryNum;
                                    }
                                }
                                ,{field:'purchaseSize',align: 'center', width:130, title: '规格'}
                                ,{field:'purStoDescAgentiaTypeName',align: 'center', width:130, title: '药剂类型'}
                                ,{field:'proPostil',align: 'center', width:130, title: '批准文号'}
                                ,{field:'purStoDescManufacturer',align: 'center', width:130, title: '生产厂商'}
                                ,{field:'supName',align: 'center', width:130, title: '供应商',templet:function (data) {
                                        return data.supplierInfo.supName;
                                    }}
                                ,{field:'purStoDescComment',align: 'center', width:163, title: '备注'}
                            ]],done:function (data) {
                            }
                        });

                        checked = true;
                    }else if (this.value == '2' && checked ==true) {
                        table.render({
                            elem: '#document-1'
                            ,url: '/searchStreamController'
                            ,height: 353
                            ,cols: [[
                                {

                                field:'purStoId',align: 'center', width:140, title: '单据号'}
                                ,{field:'purStoDate',align: 'center', width:120, title: '开单日期',templet:function (obj) {
                                        return layui.util.toDateString(obj.purchaseStock.purStoDate , 'yyyy-MM-dd');
                                    }}
                                ,{field:'proId',align: 'center', width:100, title: '商品编号'}
                                ,{field:'proName',align: 'center', width:150, title: '商品名称'}
                                ,{field:'proBid',align: 'center', width:70, title: '单价',templet:function (obj) {
                                        return obj.productInfo.proBid
                                    }}
                                ,{field:'purStoDescNum',align: 'center', width:70, title: '数量'}
                                ,{field:'productStandard',align: 'center', width:80, title: '总金额',templet:function (d) {
                                        return parseFloat(d.productInfo.proBid*d.purStoDescNum);
                                    }}
                                ,{field:'purStoDescUnit',align: 'center', width:70, title: '单位'}
                                ,{field:'proSize',align: 'center', width:80, title: '规格',templet:function (obj) {
                                        return obj.productInfo.proSize
                                    }}
                                ,{field:'proPostil',align: 'center', width:90, title: '批准文号',templet:function (obj) {
                                        return obj.productInfo.proPostil
                                    }}
                                ,{field:'depotName',align: 'center', width:100, title: '仓库',templet:function (obj) {
                                        return obj.depotInfo.depotName
                                    }}
                                ,{field:'empName',align: 'center', width:100, title: '经办人',templet:function (obj) {
                                        return obj.employeeInfo.empName
                                    }}
                                ,{field:'supName',align: 'center', width:140, title: '供货商名称',templet:function (obj) {
                                        return obj.supplierInfo.supName
                                    }}
                            ]]
                        });
                        checked = false;
                    }
                });

                $('#find-2').click(
                    function(){
                        var supName = $('#demo-2');
                        if ( "" == supName.val() ) {
                            $('input[name=supId-1]').val("");
                        }
                        if(($('#test-startDate-2').val()=="") && ($('#test-endDate-2').val()=="")){
                            layer.msg("请先选择日期");
                        }else if(($('#test-startDate-2').val()!="") && ($('#test-endDate-2').val()!="")&&($('input[name=supId-1]').val()=="" && checked==false)){
                            table.reload('document-1' , {
                                url: '/searchStreamController',
                                where: {
                                    startDate: $('#test-startDate-2').val(),
                                    endDate: $('#test-endDate-2').val()
                                }
                            });
                        }else if(($('#test-startDate-2').val()!="") && ($('#test-endDate-2').val()!="")&&($('input[name=supId-1]').val()=="" && checked==true)){
                            table.reload('document-1' , {
                                url: '/searchcollectController',
                                where: {
                                    startDate: $('#test-startDate-2').val(),
                                    endDate: $('#test-endDate-2').val()
                                }
                            });
                        } else if(($('#test-startDate-2').val()!="") && ($('#test-endDate-2').val()!="")&&($('input[name=supId-1]').val()!="" && checked==true)) {
                            table.reload('document-1' , {
                                url: '/searchcollectController',
                                where: {
                                    startDate: $('#test-startDate-2').val(),
                                    endDate: $('#test-endDate-2').val(),
                                    supId: $('input[name=supId-1]').val()
                                }
                            });
                        }else if(($('#test-startDate-2').val()!="") && ($('#test-endDate-2').val()!="")&&($('input[name=supId-1]').val()!="" && checked==false)) {
                            table.reload('document-1' , {
                                url: '/searchStreamController',
                                where: {
                                    startDate: $('#test-startDate-2').val(),
                                    endDate: $('#test-endDate-2').val(),
                                    supId: $('input[name=supId-1]').val()
                                }
                            });
                        }
                    }
                )

                table.render({
                    elem: '#document-2'
                    ,url: '/searchSaleOrderDescController'
                    ,height: 353
                    ,cols: [[
                        {field:'productId', width:100,align: 'center', title: '商品编号'}
                        ,{field:'salOrdDescProName', width:220, align: 'center',title: '商品名称'}
                        ,{field:'supName', width:120,align: 'center', title: '供货商',templet:function (data) {
								return data.supplierInfo.supName;
                            }}
                        ,{field:'salOrdDescUnit',align: 'center', width:120, title: '单位'}
                        ,{field:'salOrdDescProNum',align: 'center', width:120, title: '销售数量',templet:function (data) {
								return data.salOrdDescProNum;
                            }}
                        ,{field:'',align: 'center', width:120, title: '销售总金额',templet:function (data) {
                                return data.salOrdDescProPrice * data.salOrdDescProNum;
                            }}
                        ,{field:'inveDescInventoryNum',align: 'center', width:120, title: '库存数量',templet:function (data) {
							return	data.inveDescInventoryNum;
                            }}
                        ,{field:'',align: 'center', width:100, title: '产品规格',templet:function (data) {
								return data.productInfo.proSize;
                            }}
                        ,{field:'salOrdDescManufacturer',align: 'center', width:100, title: '生产厂商'}
                        ,{field:'salOrdDescComment',align: 'center', width:120, title: '备注'}
                    ]],done:function (data) {
                    }
                });

                $('#find-3').click(
                    function(){
                        var supName = $('#demo-3');
                        if ( "" == supName.val() ) {
                            $('input[name=supId-2]').val("");
                        }
                        if($('#test-startDate-3').val()=="" && $('#test-endDate-3').val()==""){
                            layer.msg("请先选择日期");
                        }else if($('#test-startDate-3').val()!="" && $('#test-endDate-3').val()!="" && $('input[name=supId-2]').val()==""){
                            table.reload('document-2' , {
                                url: '/searchSaleOrderDescController',
                                where: {
                                    startDate: $('#test-startDate-3').val(),
                                    endDate: $('#test-endDate-3').val()
                                }
                            });
                        }else{
                            table.reload('document-2' , {
                                url: '/searchSaleOrderDescController',
                                where: {
                                    startDate: $('#test-startDate-3').val(),
                                    endDate: $('#test-endDate-3').val(),
                                    supId: $('input[name=supId-2]').val()
                                }
                            });
                        }
                    }
                )

                table.render({
                    elem: '#document-3'
                    ,url: '/searchAccountingController'
                    ,height: 353
                    ,cols: [
                        [
                            {align: 'center' , title: '供货商商品销售情况' , colspan: 4},
                            {align: 'center' , title: '供货商账务情况' , colspan: 3}
                        ],[
                        {field:'supName', width:180,align: 'center', title: '供货商名称'
                            }
                        ,{field:'salOrdDescProNum', width:180, align: 'center',title: '商品销售额',templet:function (data) {
                                return	data.saleOrderDesc.salOrdDescProNum;
                            }}
                        ,{field:'salRetDescProNum', width:180,align: 'center', title: '商品退货额',templet:function (data) {
								return data.saleReturnDesc.salRetDescProNum;
                            }}
                        ,{field:'',align: 'center', width:180, title: '合计金额',templet:function (data) {
								return data.saleOrderDesc.salOrdDescProNum+data.saleReturnDesc.salRetDescProNum;
                            }}
                        ,{field:'',align: 'center', width:180, title: '我方应付金额',templet:function (data) {
								return data.purchaseStock.purStoPayable;
                            }}
                        ,{field:'',align: 'center', width:180, title: '我方实付金额',templet:function (data) {
								return data.purchaseStock.purStoOutof;
                            }}
                        ,{field:'proPermit',align: 'center', width:180, title: '相差金额',templet:function (data) {
								return data.purchaseStock.purStoPayable-data.purchaseStock.purStoOutof;
                            }}
                    ]]
                });
            });
		</script>
		<!--<script type="text/html" id="toolbarDemo">
			<div class="layui-btn-container">
				<button class="layui-btn layui-btn-sm" lay-event="getCheckData">删除</button>
				<button class="layui-btn layui-btn-sm" lay-event="getCheckLength">我方付款</button>
				<button class="layui-btn layui-btn-sm" lay-event="isAll">整单退货</button>
			</div>
		</script>-->
	</body>
</html>
